#!/bin/bash

index=1

echo "criando diretorios ..."
echo
for arg in "$@"
do
  echo $arg
  ssh $arg.c3sl.ufpr.br rm -r /tmp/sync.$arg
  ssh $arg.c3sl.ufpr.br mkdir /tmp/sync.$arg
  let "index+=1"
#  sleep 3
done        

echo "criando arquivos em /tmp/sync.$1/"
echo

ssh $1.c3sl.ufpr.br cat "/dev/null >/tmp/sync.$1/teste1.txt"
ssh $1.c3sl.ufpr.br cat "/dev/null >/tmp/sync.$1/teste2.txt"


echo "executando o syncp2p ... "
port=9300
FIRSTIP=$(dig $1.c3sl.ufpr.br +short)
echo "IP DO BOOTSTRAP = $FIRSTIP"
for arg in "$@"
do
  echo "Inicialndo um PEER em $arg"
  ssh $arg.c3sl.ufpr.br /usr/lib/jvm/java-6-sun-1.6.0.12/bin/java     -jar syncp2p.jar /tmp/sync.$arg $port $FIRSTIP 9300  &
  sleep 5
done        
